1. Field of the Invention
The present invention relates to the compilation of application code in a data processing apparatus.
2. Description of the Prior Art
Prior to running application code on a processor, it is first necessary to compile that application code in order to generate from the application code a sequence of instructions representing that application code, that sequence of instructions then being executed on the processor.
A well-known technique for improving the performance of fully or partially compiled code is Feedback Driven Optimisation (FDO). In accordance with this technique, the compiled code is executed on a processor of a data processing system, and the performance of that system is profiled, with this profiling information then being used by the compiler to decide how to modify the compiled code. In fully, statically, compiled languages, such as C and C++, the profiling information is collected in a test run, during which the originally compiled code is executed on a target processor. Once the test run has been completed, the profiling information is used to control the recompilation of the code by the compiler. It is the recompiled version of the code that is then subsequently used.
In dynamically compiled languages, the compiler will typically allow portions of the application code to be dynamically compiled during run time. One example of a dynamically compiled language is the JAVA™ programming language as specified by Sun Microsystems Inc. The JAVA™ programming language seeks to provide an environment in which computer software written in JAVA™ can be executed upon many different processing hardware platforms without having to alter the JAVA™ software. In JAVA™, the run-time system includes a bytecode compiler allowing the JAVA™ bytecodes (i.e. the JAVA™ application code) to be compiled at run-time into native code for the processor on which the software is running. In practice, the bytecode compiler will not compile all of the JAVA™ bytecodes, but instead the initial bytecode stream is interpreted by interpreter code, and based on the performance of the interpreted version of the application code, some of it may then be compiled by the bytecode compiler into native code.
It is possible in such dynamically compiled systems to use profiling information to select dynamically which sections of the application code should be compiled, this being known in the JAVA™ environment as Adaptive Dynamic Compilation (ADC). The aim of such ADC techniques is to improve the performance of a system as it is running.
There are a number of known techniques for obtaining the profiling information. One such technique involves “instrumentation” of the code, which involves adding additional instructions into the sequence of instructions generated by the compiler from the application code (or in the case of dynamically compiled languages such as JAVA™, adding additional instructions into the relevant parts of the interpreter code), to cause predetermined profiling information to be stored when those additional instructions are executed. As an example, the instrumentation process may involve adding an additional instruction into an instruction sequence which forms the body of a loop, whereby each time that additional instruction is encountered, it causes a counter to be incremented, thereby in effect keeping count of the number of times that loop is iterated. That piece of profiling information, along with other pieces of profiling information obtained as a result of further instructions added during the instrumentation process, can then be used to optimise the compilation by the compiler.
An alternative to the instrumentation approach is to use sample based profiling techniques, which involve interrupting the processor at predetermined points to enable performance counters to be read via a JTAG interface, or to be saved into memory. More details on feedback driven optimisation is provided in the article “Feedback directed optimisation in Compaq's compilation tools for Alpha” by Robert Cohn et al, which appeared in the 2nd ACM Workshop on Feedback-Directed Optimisation, Haifa, Israel, Nov. 15, 1999.
The problem with both of the above techniques is that they are intrusive, and significantly alter the behaviour of, and slow down, the code that they are attempting to optimise. For instance, the instrumentation technique involves adding additional instructions into the instruction sequence which hence materially alters the instruction sequence. Similarly, the sample based profiling technique involves interrupting the execution at predetermined points, which would not occur during normal execution of the compiled code. Hence, both techniques tend to adversely affect the accuracy of the information collected, particularly in real-time systems. Furthermore, in dynamic compilation implementations such as the above described JAVA™ case, the amount of information collected to decide what to compile has to be carefully balanced against the cost (e.g. in terms of performance, increased size of code, etc) of collecting that information.
It would hence be desirable to provide an improved technique for obtaining profiling information for use in such FDO techniques.